#include <iostream>
using namespace std;
int cnt[3], a[3];
const int mod = 1e9 + 7;

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        a[0] = cnt[0], a[1] = cnt[1], a[2] = cnt[2];
        int t = (s[i] - '0') % 3;
        a[t]++;
        for(int i = 0; i < 3; i++){
            cnt[(i + t) % 3] = (a[i] + cnt[(i + t) % 3]) % mod;
        }
        
    }
    cout << cnt[0] << endl;
    return 0;
}